<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:isc="http://extension-functions.intersystems.com" xmlns:hl7="urn:hl7-org:v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:exsl="http://exslt.org/common" exclude-result-prefixes="isc hl7 xsi exsl">

		
	<!-- 高值耗材章节 -->
	<xsl:template match="*" mode="HighValueConsumableSection">
		<xsl:choose>
			<xsl:when test="($hccDocType='C0022')">
				<xsl:apply-templates select="$sectionRootPath[hl7:code/@code=$hcc_HistoryOfMedicationUse]" mode="HighValueConsumableEntry">
				</xsl:apply-templates>
			</xsl:when>
		</xsl:choose>
	</xsl:template>
	<!-- 高值耗材章节条目 -->
	<xsl:template match="*" mode="HighValueConsumableEntry">
		<xsl:apply-templates select="hl7:entry" mode="HCCOtherOrder">
			<xsl:with-param name="sectionType" select="'HMU'"/>
		</xsl:apply-templates>
	</xsl:template>
	
	<!-- 出院诊断章节 -->
	<xsl:template match="*" mode="DischargeDxOrderSection">
		<xsl:choose>
			<xsl:when test="($hccDocType='C0049')">
				<xsl:apply-templates select="$sectionRootPath[hl7:code/@code=$hcc_HospitalDischargeDX]" mode="DischargeDxOrderEntry"></xsl:apply-templates>
			</xsl:when>
		</xsl:choose>
	</xsl:template>
	<!-- 出院诊断章节条目 - 出院医嘱 -->
	<xsl:template match="*" mode="DischargeDxOrderEntry">
		<xsl:apply-templates select="hl7:entry/hl7:observation[hl7:code/@code='DE06.00.287.00']" mode="HCCOtherOrder">
			<xsl:with-param name="sectionType" select="'DDO'"/>
		</xsl:apply-templates>
	</xsl:template>
	
	
	<!--通用other order条目输出模板-->
	<xsl:template match="*" mode="HCCOtherOrder">
		<xsl:param name = "sectionType" />
		<xsl:choose>
			<xsl:when test="$sectionType='HMU'">
				<xsl:variable name="productId"><xsl:value-of select="hl7:substanceAdministration/hl7:consumable/hl7:manufacturedProduct/hl7:id/@extension"/></xsl:variable>
				<OtherOrder>
					<EncounterNumber><xsl:value-of select="$encompassingEncounterID"/></EncounterNumber>
					<ExternalId><xsl:value-of select="concat($hccDocNo,'-',$sectionType,'-',position())"/></ExternalId>
					<OrderItem>
					<xsl:choose>
					<xsl:when test="string-length($productId)">
						<Code><xsl:value-of select="$productId"/></Code>
					</xsl:when>
					<xsl:otherwise>
						<Code><xsl:value-of select="hl7:substanceAdministration/hl7:consumable/hl7:manufacturedProduct/hl7:manufacturedMaterial/hl7:code"/></Code>
					</xsl:otherwise>
					</xsl:choose>
						<Description><xsl:value-of select="hl7:substanceAdministration/hl7:consumable/hl7:manufacturedProduct/hl7:manufacturedMaterial/hl7:name"/></Description>
					</OrderItem>
					<OrderQuantity>
						<xsl:value-of select="hl7:substanceAdministration/hl7:doseQuantity/@value"/>
					</OrderQuantity>
					<OrderCategory>
						<Code><xsl:value-of select="'高值耗材'"/></Code>
						<Description><xsl:value-of select="'高值耗材'"/></Description>
					</OrderCategory>
				</OtherOrder>
			</xsl:when>
			<xsl:when test="$sectionType='DDO'">
				<OtherOrder>
					<EncounterNumber><xsl:value-of select="$encompassingEncounterID"/></EncounterNumber>
					<ExternalId><xsl:value-of select="concat($hccDocNo,'-',$sectionType,'-',position())"/></ExternalId>
					<TextInstruction><xsl:value-of select="hl7:value"/></TextInstruction>
					<OrderItem>
					<Code><xsl:value-of select="'出院医嘱'"/></Code>
						<Description><xsl:value-of select="'出院医嘱'"/></Description>
					</OrderItem>
					<OrderCategory>
						<Code><xsl:value-of select="'出院医嘱'"/></Code>
						<Description><xsl:value-of select="'出院医嘱'"/></Description>
					</OrderCategory>
				</OtherOrder>
			</xsl:when>
		</xsl:choose>		
	</xsl:template>
	
</xsl:stylesheet>
